﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCA.Community.DAL.Interfaces;
using System.Data.Services.Client;
using LCA.Community.DAL.Model;

namespace LCA.Community.DAL.Test.Mocks
{
    /// <summary>
    /// Mock for IDataServiceContext
    /// </summary>
    public class FakeDataServiceContext<T> : IDataServiceContext<T> where T : BasicDataModel
    {
        private static List<T> _entities;

        public FakeDataServiceContext()
        {
            if(_entities == null) _entities = new List<T>();
            TableName = typeof(T).Name;
        }

        public void AddObject(string entitySetName, object entity)
        {
            var model = (T)entity;
            model.Timestamp = DateTime.Now;
            _entities.Add(model);
        }

        public void DeleteObject(object entity)
        {
            var model = (T)entity;
            _entities.Remove(model);
        }

        public void TryAttachTo(T entity)
        {
            
        }

        public void UpdateObject(object entity)
        {
            DeleteObject(entity);
            AddObject("",entity);
        }

        public DataServiceResponse SaveChanges()
        {
            return null;
        }

        public IQueryable<T> TableEntities
        {
            get 
            {
                return _entities.AsQueryable();
            }
        }

        public string TableName { get; private set; }
    }
}
